package com.by.toolkit.enums;

import com.by.toolkit.consts.GlobalConst;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Getter
@AllArgsConstructor
public enum WxCpAddWayEnum {

    // 企微没有活码枚举值，自定义一下-10
    DYNAMIC_QRCODE(-10, "活码"),
    // 企微没有活码枚举值，自定义一下--100，没有实际意义
    OTHER(-100, "其他添加方式"),
    // 以下是企微的数据
    UNKNOWN(0, "未知来源"),
    SCAN_QRCODE(1, "扫描二维码"),
    SEARCH_PHONE(2, "搜索手机号"),
    MING_PIAN(3, "名片分享"),
    GROUP_INNER_ADD(4, "群聊"),
    PHONE_CONTRACT(5, "手机通讯录"),
    WECHAT(6, "微信联系人"),
    THIRD_APP(8, "安装第三方应用时自动添加的客服人员"),
    SEARCH_EMAIL(9, "搜索邮箱"),
    VIDEO(10, "视频号添加"),
    RI_CHENG(11, "通过日程参与人添加"),
    HUI_YI(12, "通过会议参与人添加"),
    WECHAT_FRIEND_WX_CP(13, "添加微信好友对应的企业微信"),
    ZHIHUI_YINGJIAN(14, "通过智慧硬件专属客服添加"),
    SHANG_MEN(15, "通过上门服务客服添加"),
    CUSTOMER_ACQUISITION_LONK(16, "通过获客链接添加"),
    DING_ZHI(17, "通过定制开发添加"),
    HUIFU(18, "通过需求回复添加"),
    THIRD_KEFU(21, "通过第三方售前客服添加"),
    BUSINESS_PARTY(22, "通过可能的商务伙伴添加"),
    WX_ACCOUNT(24, "通过接受微信账号收到的好友申请添加"),
    FEN_XIANG(201, "内部成员共享"),
    ADMIN_DIVIDE(202, "管理员/负责人分配"),
    ;

    private Integer code;

    private String desc;

    public static final Map<Integer, WxCpAddWayEnum> MAP = Stream.of(WxCpAddWayEnum.values())
            .collect(Collectors.toMap(WxCpAddWayEnum::getCode, Function.identity()));

    public static WxCpAddWayEnum resolve(Integer code) {
        return MAP.get(code);
    }

    public static String resolve2Desc(Integer code) {
        WxCpAddWayEnum wxCpAddWayEnum = MAP.get(code);
        if (Objects.isNull(wxCpAddWayEnum)) {
            return GlobalConst.UNKNOWN_STR;
        }
        return wxCpAddWayEnum.getDesc();
    }

}
